package com.test.selenium;

import org.openqa.selenium.phantomjs.PhantomJSDriver;
import org.openqa.selenium.phantomjs.PhantomJSDriverService;
import org.openqa.selenium.remote.DesiredCapabilities;

/**
 * @Author lizhilong
 * @create 2020/1/7 18:21
 * @desc
 */
public class MyPhanTomJsDriver {

    private static final String DRIVER_URL = "C:\\Imageurl\\phantomjs-2.1.1-windows\\bin\\phantomjs.exe";
    private static PhantomJSDriver phantomJSDriver = null;

    public static PhantomJSDriver getWebDriver() {
        System.setProperty("webdriver.chrome.driver", DRIVER_URL);
        System.setProperty("phantomjs.binary.path", DRIVER_URL);

        DesiredCapabilities dcaps = new DesiredCapabilities();
        //ssl 支持
        dcaps.setCapability("acceptSslCerts", true);
        //截屏支持
        dcaps.setCapability("takesScreenshot", true);
        //css搜索支持
        dcaps.setCapability("cssSelectorsEnabled", true);
        //js支持
        dcaps.setJavascriptEnabled(true);
        //驱动支持
        dcaps.setCapability(PhantomJSDriverService.PHANTOMJS_EXECUTABLE_PATH_PROPERTY, DRIVER_URL);
        //创建无界面浏览器对象


        phantomJSDriver =  new PhantomJSDriver(dcaps);
        return  phantomJSDriver;

    }

    public static   void  close(){
        if(phantomJSDriver !=null){
            phantomJSDriver.close();
        }
    }
}
